package com.eliza.lifecycle.observer

import android.util.Log
import androidx.lifecycle.*


/*
* 如果一个观察者同时实现了DefaultLifecycleObserver和DefaultLifecycleObserver，
* DefaultLifecycleObserver要先于LifecycleEventObserver的onStateChanged调用。
*   如果也添加了OnLifecycleEvent注解。那么注解会被忽略掉。
* */
class NewLifecycleEventObserver : LifecycleEventObserver {
    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        when (event) {
            Lifecycle.Event.ON_CREATE -> Log.e(this::class.java.name, "==>ON_CREATE")
            Lifecycle.Event.ON_RESUME -> Log.e(this::class.java.name, "==>ON_RESUME")
            Lifecycle.Event.ON_PAUSE -> Log.e(this::class.java.name, "==>ON_PAUSE")
            Lifecycle.Event.ON_DESTROY -> Log.e(this::class.java.name, "==>ON_DESTROY")
            Lifecycle.Event.ON_STOP -> Log.e(this::class.java.name, "==>ON_STOP")
            Lifecycle.Event.ON_START -> Log.e(this::class.java.name, "==>ON_START")
            Lifecycle.Event.ON_ANY -> Log.e(this::class.java.name, "==>ON_ANY")
            else -> Log.e(this::class.java.name, "==>Null")
        }
    }


}